using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ALC.Core.ViewModels.GraphicPack;
using HalconDotNet;

namespace ALC.Views.GraphicPack
{
    public partial class GraphicPackListView : UserControl
    {
        private IList<GraphicPackView> _screens;
        
        public GraphicPackListView()
        {
            InitializeComponent();
            Loaded += OnGraphicPackListViewLoaded;
        }

        private void OnGraphicPackListViewLoaded(object sender, RoutedEventArgs e)
        {
            if (_screens != null) return;
            
            _screens = new List<GraphicPackView>()
            {
                PART_Screen1,
                PART_Screen2,
                PART_Screen3
            };
        }

        public static readonly DependencyProperty GraphicPacksProperty = DependencyProperty.Register(
            "GraphicPacks", typeof(IList<GraphicPackViewModel>), typeof(GraphicPackListView), new PropertyMetadata(default(IList<GraphicPackViewModel>), OnGraphicPacksPropertyChanged));

        private static void OnGraphicPacksPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var view = (GraphicPackListView) d;
            var newValue = (IList<GraphicPackViewModel>) e.NewValue;
            if (newValue == null) return;

            for (int i = 0; i < newValue.Count; i++)
            {
                view._screens[i].GraphicPack = newValue[i];
            }
        }

        public IList<GraphicPackViewModel> GraphicPacks
        {
            get { return (IList<GraphicPackViewModel>) GetValue(GraphicPacksProperty); }
            set { SetValue(GraphicPacksProperty, value); }
        }
        
    }
}